From 7e4043951bfee9ac2f44a888aae0c9324df29f58 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Fri, 19 Aug 2016 13:36:32 -0700 Subject: [PATCH] Add a temporary env var to enable hashes in filenames For rustbuild we need the hashes to exist for all deps, even if they're path deps, because we care about the actual file names. For example we don't want to install /usr/lib/libstd.so! This adds a "secret" environment variable, `__CARGO_DEFAULT_LIB_METADATA` which re-enables the old behavior of just putting hashes in filenames. Closes #3005 --- src/cargo/ops/cargo_rustc/context.rs | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/src/cargo/ops/cargo_rustc/context.rs b/src/cargo/ops/cargo_rustc/context.rs index af915c224..922da9ccd 100644 --- a/src/cargo/ops/cargo_rustc/context.rs +++ b/src/cargo/ops/cargo_rustc/context.rs @@ -335,11 +335,30 @@ impl<'a, 'cfg> Context<'a, 'cfg> { Some(metadata) } else if unit.pkg.package_id().source_id().is_path() && !unit.profile.test { - // If we're not building a unit test then the root package never - // needs any metadata as it's guaranteed to not conflict with any - // other output filenames. This means that we'll have predictable + // If we're not building a unit test but we're building a path + // dependency, then we're likely compiling the "current package" or + // some package in a workspace. In this situation we pass no + // metadata by default so we'll have predictable // file names like `target/debug/libfoo.{a,so,rlib}` and such. - None + // + // Note, though, that the compiler's build system at least wants + // path dependencies to have hashes in filenames. To account for + // that we have an extra hack here which reads the + // `__CARGO_DEFAULT_METADATA` environment variable and creates a + // hash in the filename if that's present. + // + // This environment variable should not be relied on! It's basically + // just here for rustbuild. We need a more principled method of + // doing this eventually. + if unit.target.is_lib() { + env::var("__CARGO_DEFAULT_LIB_METADATA").ok().map(|meta| { + let mut metadata = unit.pkg.generate_metadata(); + metadata.mix(&meta); + metadata + }) + } else { + None + } } else { metadata.cloned() } -- 2.30.2